#ifndef _ANIMATION_H_
#define _ANIMATION_H_

#include "Widget.h"
#include "misc.h"

namespace animationagent {

const size_t MAX_BUFFER_SIZE = 64;
class AnimationSequence 
{
public:
    enum AnimationStyle {
        LOOP,
        ONCE
    };
    char name[MAX_BUFFER_SIZE];
    Uint32 anim_rate_msec;
    Uint16 pindex;
    enum AnimationStyle playstyle;
    misc::SimpleVector<Uint16> index_array;

    AnimationSequence(char *n);
    ~AnimationSequence();
    void set_frame_rate(Uint32 msec);
    void set_playstyle(enum AnimationStyle style);
    void append_index(Uint16 i);
    Uint16 get_next_frame_index();
    void reset();
};

class Animation : public Widget
{
public:

    void add_frame(SDL_Surface *frame);
    void add_sequence(AnimationSequence *seq);
    void set_current_sequence(Sint32 i);
    //void set_current_frame(Uint16 i);
    virtual void draw(SDL_Surface *screen);
    virtual void update();
    //virtual void set_colorkey(Uint8 r, Uint8 g, Uint8 b);
    //virtual void set_alpha(Uint8 a);
    void play(char *name);
    void play(int seq_index);
    void pause();
    Animation();
    Animation(Sint32 size);
    virtual ~Animation();

protected:


private:
    misc::SimpleVector<SDL_Surface *> frames;
    misc::SimpleVector<AnimationSequence *> sequences;
    /*for animation*/
    Uint32      anim_oldtime_msec;
    //Uint32      anim_rate_msec;
    Uint16      current_frame;
    Sint32      current_sequence;
    void init();
};


}
#endif
